#include<unistd.h>
#include <stdio.h>
#include <string.h>
#include <c++/v1/cstdlib>


int main()
{
    int* p = malloc(sizeof(int));

    *p = 1;

    if (fork())
    {
        int n= 0;
        while (1)
        {
            while (*p); //*p为1就卡主
            printf("父进程%d\n",n++);
            sleep(1);
        }
    }else
    {
        char c;
        while (1)
        {
                read(0,&c,1);
                if (c== 10)
                {
                    if (*p=1)
                    {
                        *p=0;
                    }else
                    {
                        *p=1;
                    }
                }
        }
    }

    return 0;
}
